//
//  DetailSheetViewController.m
//  Contractor
//
//  Created by 金鑫 on 16/5/20.
//  Copyright © 2016年 star j. All rights reserved.
//

#import "DetailSheetViewController.h"
#import "CONST.h"
#import "MBProgressHUD.h"
#import "DetailSheetModle.h"
#import "PicModel.h"
#import "PasswordField.h"
#import "ServiceListTableViewCell.h"
#import "TZImagePickerController.h"
#import "TZImageManager.h"
#import "PreviewViewController.h"
#import "RefuseViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>

@interface DetailSheetViewController ()<UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource,TZImagePickerControllerDelegate>
{
    DetailSheetModle *detailModel ;
    UIScrollView *ScrollView ;
    UIView *gdimageView ;
    UIView *gdDoneView ;
    PasswordField *field ;
    UIView *mainView ;
    UIView *alterview ;
    UIImageView *orderTimeBackView ;
    UITextField *yearfield ;
    UITextField *monthfield ;
    UITextField *dayfield ;
    UIButton *morningBtn ;
    UIButton *afternoonBtn ;
    UIButton *nightBtn ;
    UIButton *alldayBtn ;
    NSString *beginTime ;
    NSString *endTime ;
    UIWebView *phoneCallWebView ;
    NSMutableArray *_selectedPhotos ;
    NSMutableArray *_selectedAssets ;
    BOOL _isSelectOriginalPhoto ;
    NSInteger noimageCount ;
    NSMutableArray *picfirstArray ;
    NSMutableArray *piclaterArray ;
    NSMutableArray *imageUrlArray ;
    NSMutableArray *serviceArray ;
}

@end

@implementation DetailSheetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated
{
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;
    self.view.backgroundColor = [UIColor whiteColor] ;
    self.navigationItem.title = @"工单详情" ;
    NSLog(@"gdstatusID:%@",_gdstatus) ;
    if ([_gdstatus integerValue] != 9) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        btn.frame =CGRectMake(0, 0, 30, 30);
        
        [btn setBackgroundImage:[UIImage imageNamed:@"title_refresh_btn_icon.png"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(downloadDetail) forControlEvents:UIControlEventTouchUpInside] ;
        
        UIBarButtonItem *noticeItem = [[UIBarButtonItem alloc] initWithCustomView:btn] ;
        
        self.navigationItem.rightBarButtonItem = noticeItem ;
    }
    
    detailModel = [[DetailSheetModle alloc] init] ;
    [self downloadDetail] ;
}

#pragma mark - 加在数据
- (void)downloadDetail
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = NSLocalizedString(@"正在努力加载", @"HUD loading title") ;
    
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:6] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    
    NSDictionary *jsondic = @{@"gdorderid":self.gdorderId} ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    NSLog(@"%@",jsondic) ;
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr};
    
    NSLog(@"parameters:%@",parameters) ;
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         [hud hideAnimated:YES] ;
         //解密并解析json数据，将json转成字典
         NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         
         decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
         id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
         //获取字典中的值
         if ([result isKindOfClass:[NSDictionary class]])
         {
             NSDictionary *dic = result ;
             NSLog(@"通知:%@",dic) ;
             if ([dic[@"status"]integerValue] == 1) {
                 NSDictionary *contentDic = dic[@"content"] ;
                 for (NSDictionary *gdorderinfoDic in contentDic[@"gdorderinfo"]) {
                     [detailModel setValuesForKeysWithDictionary:gdorderinfoDic] ;//取到gdorderinfo数据
                 }
                 for (NSDictionary *consumerArrayDic in contentDic[@"consumerArray"]) {
                     [detailModel setValuesForKeysWithDictionary:consumerArrayDic] ;//取得consumerArray数据
                 }
                 for (NSDictionary *serviceArrayDic in contentDic[@"serviceArray"]) {
                     [detailModel setValuesForKeysWithDictionary:serviceArrayDic] ;//取得serviceArray数据
                 }

                 detailModel.pictureArray = contentDic[@"pictureArray"] ;
                 detailModel.serviceArray = contentDic[@"serviceArray"] ;
                 
                 serviceArray = [NSMutableArray array] ;
                 for (NSDictionary *dic in detailModel.serviceArray) {
                     DetailSheetModle *model = [[DetailSheetModle alloc] init] ;
                     [model setValuesForKeysWithDictionary:dic] ;
                     [serviceArray addObject:model] ;
                 }

                 [self createView] ;
             }
         }
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"Error: %@", error);
     }];
}

- (void)downloadOfJiedan
{
    [self removeMainView] ;
    
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:205] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    
    
    NSNumber *accepttype = [[NSNumber alloc] initWithInt:1] ;
    
    NSDictionary *jsondic = @{@"gdorderid":detailModel.orderid,
                              @"accepttype":accepttype,
                              @"memo":@"接单"
                              } ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    NSLog(@"%@",jsondic) ;
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr};
    //    NSLog(@"%@",parameters) ;
    
    // NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid};
    NSLog(@"parameters:%@",parameters) ;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         //解密并解析json数据，将json转成字典
         NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         
         decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
         id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
         //获取字典中的值
         if ([result isKindOfClass:[NSDictionary class]])
         {
             NSDictionary *dic = result ;
             NSLog(@"通知:%@",dic) ;
             if ([dic[@"status"]integerValue] == 1) {
                 [self downloadDetail] ;
             }
         }
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         
         NSLog(@"Error: %@", error);
     }];
}


- (void)downloadOfOrder:(NSString *)orderid beginTime:(NSString *)begintime endTime:(NSString *)endtime
{
    
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:207] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    NSDictionary *jsondic = @{@"gdorderid":orderid,
                              @"gdSetServiceTimeBegin":begintime,
                              @"gdSetServiceTimeEnd":endtime,
                              @"memo":@""
                              } ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    NSLog(@"%@",jsondic) ;
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr} ;
    NSLog(@"parameters:%@",parameters) ;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         //解密并解析json数据，将json转成字典
         NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         
         decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
         id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
         //获取字典中的值
         if ([result isKindOfClass:[NSDictionary class]])
         {
             NSDictionary *dic = result ;
             NSLog(@"通知:%@",dic) ;
             if ([dic[@"status"]integerValue] == 1) {
                 [self downloadDetail] ;
             }
         }
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"Error: %@", error);
     }];
    
}


- (void)downloadOfDoorUP
{
    [self removeMainView] ;
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:208] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    NSDictionary *jsondic = @{@"gdorderid":detailModel.orderid,
                              @"memo":@"上门服务"
                              } ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr};
    NSLog(@"parameters:%@",parameters) ;
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = NSLocalizedString(@"正在努力加载...", @"HUD loading title") ;
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         [hud hideAnimated:YES] ;
         //解密并解析json数据，将json转成字典
         NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         
         decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
         id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
         //获取字典中的值
         if ([result isKindOfClass:[NSDictionary class]])
         {
             NSDictionary *dic = result ;
             NSLog(@"通知:%@",dic) ;
             if ([dic[@"status"]integerValue] == 1) {
                 [self downloadDetail] ;
             }
         }
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [hud hideAnimated:YES] ;
         NSLog(@"Error: %@", error);
     }];
}


//上门验证码接口
- (void)downloadOfDoorYz
{
    [field resignFirstResponder] ;
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    NSLog(@"gdorderid:%@",detailModel.orderid) ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:217] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    NSDictionary *jsondic = @{@"gdorderid":detailModel.orderid,
                              @"servicecode":field.text,
                              @"memo":@"上门服务"
                              } ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    NSLog(@"%@",jsondic) ;
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr};
    NSLog(@"parameters:%@",parameters) ;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    if (field.text.length == 0) {
        UIButton *errorbtn = [[UIButton alloc] initWithFrame:CGRectMake((__kScreenWidth - 100)/2, __kScreenHeight - 80, 100, 50)] ;
        [errorbtn setTitle:@"输入不能为空" forState:UIControlStateNormal] ;
        errorbtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:14.0f] ;
        errorbtn.layer.cornerRadius = 10 ;
        errorbtn.backgroundColor = [UIColor blackColor] ;
        errorbtn.alpha = 0.8 ;
        [[UIApplication sharedApplication].keyWindow addSubview:errorbtn] ;
        [self performSelector:@selector(clearbtn:) withObject:errorbtn afterDelay:2.0] ;
    }
    else
    {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.label.text = NSLocalizedString(@"正在努力加载...", @"HUD loading title") ;
        [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
         {
             [hud hideAnimated:YES] ;
             //解密并解析json数据，将json转成字典
             NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
             NSLog(@"decodeStr:%@",decodeStr) ;
             
             decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
             NSLog(@"decodeStr:%@",decodeStr) ;
             NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
             id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
             //获取字典中的值
             if ([result isKindOfClass:[NSDictionary class]])
             {
                 NSDictionary *dic = result ;
                 NSLog(@"通知:%@",dic) ;
                 if ([dic[@"status"]integerValue] == 1) {
                     [self downloadDetail] ;
                 }
                 else{
                     UIButton *errorbtn = [[UIButton alloc] initWithFrame:CGRectMake((__kScreenWidth - 100)/2, __kScreenHeight - 80, 100, 50)] ;
                     [errorbtn setTitle:@"工单操作失败" forState:UIControlStateNormal] ;
                     errorbtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:14.0f] ;
                     errorbtn.layer.cornerRadius = 10 ;
                     errorbtn.backgroundColor = [UIColor blackColor] ;
                     errorbtn.alpha = 0.8 ;
                     [[UIApplication sharedApplication].keyWindow addSubview:errorbtn] ;
                     [self performSelector:@selector(clearbtn:) withObject:errorbtn afterDelay:2.0] ;
                 }
             }
         }
              failure:^(AFHTTPRequestOperation *operation, NSError *error)
         {
             [hud hideAnimated:YES] ;
             NSLog(@"Error: %@", error);
         }];
        
    }

}

//完成工单接口
- (void)downloadOfHavedone
{
    [self removeMainView] ;
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    NSLog(@"gdorderid:%@",detailModel.orderid) ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:209] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    NSDictionary *jsondic = @{@"gdorderid":detailModel.orderid,
                              @"memo":@"工单完成"
                              } ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    NSLog(@"%@",jsondic) ;
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr};
    NSLog(@"parameters:%@",parameters) ;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = NSLocalizedString(@"正在努力加载...", @"HUD loading title") ;
    [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         [hud hideAnimated:YES] ;
         //解密并解析json数据，将json转成字典
         NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         
         decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
         id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
         //获取字典中的值
         if ([result isKindOfClass:[NSDictionary class]])
         {
             NSDictionary *dic = result ;
             NSLog(@"通知:%@",dic) ;
             if ([dic[@"status"]integerValue] == 1) {
                 [self downloadDetail] ;
             }
             else{
                 UIButton *errorbtn = [[UIButton alloc] initWithFrame:CGRectMake((__kScreenWidth - 100)/2, __kScreenHeight - 80, 100, 50)] ;
                 [errorbtn setTitle:@"工单操作失败" forState:UIControlStateNormal] ;
                 errorbtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:14.0f] ;
                 errorbtn.layer.cornerRadius = 10 ;
                 errorbtn.backgroundColor = [UIColor blackColor] ;
                 errorbtn.alpha = 0.8 ;
                 [[UIApplication sharedApplication].keyWindow addSubview:errorbtn] ;
                 [self performSelector:@selector(clearbtn:) withObject:errorbtn afterDelay:2.0] ;
             }
         }
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [hud hideAnimated:YES] ;
         NSLog(@"Error: %@", error);
     }];
}

//完工验证接口（工单完成客户评价）
- (void)downloadOfhaveDoneYz
{
    [field resignFirstResponder] ;
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    NSLog(@"gdorderid:%@",detailModel.orderid) ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:219] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    NSDictionary *jsondic = @{@"gdorderid":detailModel.orderid,
                              @"servicecommentscode":field.text,
                              @"memo":@"工单完成客户评价"
                              } ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    NSLog(@"%@",jsondic) ;
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr};
    NSLog(@"parameters:%@",parameters) ;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    if (field.text.length == 0) {
        UIButton *errorbtn = [[UIButton alloc] initWithFrame:CGRectMake((__kScreenWidth - 120)/2, __kScreenHeight - 80, 120, 50)] ;
        [errorbtn setTitle:@"输入不能为空！" forState:UIControlStateNormal] ;
        errorbtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:14.0f] ;
        errorbtn.layer.cornerRadius = 10 ;
        errorbtn.backgroundColor = [UIColor blackColor] ;
        errorbtn.alpha = 0.8 ;
        [[UIApplication sharedApplication].keyWindow addSubview:errorbtn] ;
        [self performSelector:@selector(clearbtn:) withObject:errorbtn afterDelay:2.0] ;
    }
    else
    {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.label.text = NSLocalizedString(@"正在努力加载...", @"HUD loading title") ;
        [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
         {
             [hud hideAnimated:YES] ;
             //解密并解析json数据，将json转成字典
             NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
             NSLog(@"decodeStr:%@",decodeStr) ;
             
             decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
             NSLog(@"decodeStr:%@",decodeStr) ;
             NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
             id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
             //获取字典中的值
             if ([result isKindOfClass:[NSDictionary class]])
             {
                 NSDictionary *dic = result ;
                 NSLog(@"通知:%@",dic) ;
                 if ([dic[@"status"]integerValue] == 1) {
                     [self downloadDetail] ;
                 }
                 else{
                     UIButton *errorbtn = [[UIButton alloc] initWithFrame:CGRectMake((__kScreenWidth - 100)/2, __kScreenHeight - 80, 100, 50)] ;
                     [errorbtn setTitle:@"工单操作失败" forState:UIControlStateNormal] ;
                     errorbtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:14.0f] ;
                     errorbtn.layer.cornerRadius = 10 ;
                     errorbtn.backgroundColor = [UIColor blackColor] ;
                     errorbtn.alpha = 0.8 ;
                     [[UIApplication sharedApplication].keyWindow addSubview:errorbtn] ;
                     [self performSelector:@selector(clearbtn:) withObject:errorbtn afterDelay:2.0] ;
                 }
             }
         }
              failure:^(AFHTTPRequestOperation *operation, NSError *error)
         {
             [hud hideAnimated:YES] ;
             NSLog(@"Error: %@", error);
         }];
        
    }
}

- (void)downloadOfPicUrl:(NSString *)url withpicData:(NSData *)imageData isRefresh:(BOOL)isrefresh
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    //NSLog(@"paths : %@",paths) ;
    
    
    //给照片按拍摄时间命名
    NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"images.jpg"]]; ;
    
    [imageData writeToFile: uniquePath atomically:YES];
    
    // NSData *pathdata = [NSData dataWithContentsOfFile:uniquePath] ;
    //[pathdata writeToFile:uniquePath atomically:YES] ;
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = NSLocalizedString(@"正在努力加载...", @"HUD loading title") ;
    
    [manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        // [formData appendPartWithFormData:imageData name:@""] ;
        [formData appendPartWithFileData:imageData name:@"gdpic" fileName:uniquePath mimeType:@"image/jpeg"] ;
        
    } success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
        NSLog(@"ImagebackStr:%@",decodeStr) ;
        
        id result = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil] ;
        
        if ([result isKindOfClass:[NSDictionary class]]) {
            NSDictionary *dic = result ;
            NSLog(@"图片上传成功:%@",dic) ;
            if ([dic[@"status"] integerValue] == 1) {
                if (isrefresh) {
                    [self downloadOfUploadPic] ;
                }
            }
        }
    } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
        NSLog(@"上传失败：%@",error) ;
    }] ;
    
}

- (void)downloadOfUploadPic
{
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    NSLog(@"gdorderid:%@",detailModel.orderid) ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:213] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    NSNumber *status = [[NSNumber alloc] initWithInteger:20] ;
    
    NSDictionary *jsondic = @{@"gdorderid":detailModel.orderid,
                              @"gdstatus":status,
                              @"memo":@"上传图片"
                              } ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    NSLog(@"%@",jsondic) ;
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr};
    NSLog(@"parameters:%@",parameters) ;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = NSLocalizedString(@"正在努力加载...", @"HUD loading title") ;
    
    [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         [hud hideAnimated:YES] ;
         //解密并解析json数据，将json转成字典
         NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         
         decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
         id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
         //获取字典中的值
         if ([result isKindOfClass:[NSDictionary class]])
         {
             NSDictionary *dic = result ;
             NSLog(@"通知:%@",dic) ;
             if ([dic[@"status"]integerValue] == 1) {
                 [self downloadDetail] ;
             }
             else{
                 UIButton *errorbtn = [[UIButton alloc] initWithFrame:CGRectMake((__kScreenWidth - 100)/2, __kScreenHeight - 80, 100, 50)] ;
                 [errorbtn setTitle:@"工单操作失败" forState:UIControlStateNormal] ;
                 errorbtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:14.0f] ;
                 errorbtn.layer.cornerRadius = 10 ;
                 errorbtn.backgroundColor = [UIColor blackColor] ;
                 errorbtn.alpha = 0.8 ;
                 [[UIApplication sharedApplication].keyWindow addSubview:errorbtn] ;
                 [self performSelector:@selector(clearbtn:) withObject:errorbtn afterDelay:2.0] ;
             }
         }
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [hud hideAnimated:YES] ;
         NSLog(@"Error: %@", error);
     }];

}

- (void)downloadOfDeletePic:(PicModel *)model
{
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    NSLog(@"gdorderid:%@",detailModel.orderid) ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:218] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    
    NSDictionary *jsondic = @{@"gdorderid":detailModel.orderid,
                              @"picname":model.picname,
                              @"pictype": @"1"
                              } ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    NSLog(@"%@",jsondic) ;
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr};
    NSLog(@"parameters:%@",parameters) ;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = NSLocalizedString(@"正在努力加载...", @"HUD loading title") ;
    
    [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         [hud hideAnimated:YES] ;
         //解密并解析json数据，将json转成字典
         NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         
         decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
         id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
         //获取字典中的值
         if ([result isKindOfClass:[NSDictionary class]])
         {
             NSDictionary *dic = result ;
             NSLog(@"通知:%@",dic) ;
             if ([dic[@"status"]integerValue] == 1) {
                 [self downloadDetail] ;
             }
             else{
                 UIButton *errorbtn = [[UIButton alloc] initWithFrame:CGRectMake((__kScreenWidth - 100)/2, __kScreenHeight - 80, 100, 50)] ;
                 [errorbtn setTitle:@"工单操作失败" forState:UIControlStateNormal] ;
                 errorbtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:14.0f] ;
                 errorbtn.layer.cornerRadius = 10 ;
                 errorbtn.backgroundColor = [UIColor blackColor] ;
                 errorbtn.alpha = 0.8 ;
                 [[UIApplication sharedApplication].keyWindow addSubview:errorbtn] ;
                 [self performSelector:@selector(clearbtn:) withObject:errorbtn afterDelay:2.0] ;
             }
         }
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [hud hideAnimated:YES] ;
         NSLog(@"Error: %@", error);
     }];

}


- (void)downloadOfhaveDoneOfFinish
{
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    NSLog(@"gdorderid:%@",detailModel.orderid) ;
    
    NSNumber *cmd = [[NSNumber alloc] initWithInt:220] ;
    NSNumber *uid = [[NSNumber alloc] initWithInteger:uidInt] ;
    NSDictionary *jsondic = @{@"gdorderid":detailModel.orderid,
                              @"memo":@"确认完工"
                              } ;
    NSLog(@"%@",jsondic) ;
    
    NSString *jsonstr =  [CodeWithDES encodeWithDic:jsondic] ;
    NSLog(@"%@",jsondic) ;
    NSLog(@"%@",jsonstr) ;
    NSDictionary *parameters = @{@"cmd":cmd, @"uid":uid, @"jsonstr":jsonstr};
    NSLog(@"parameters:%@",parameters) ;
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.label.text = NSLocalizedString(@"正在努力加载...", @"HUD loading title") ;
    
    [manager POST:getAppJson parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         [hud hideAnimated:YES] ;
         //解密并解析json数据，将json转成字典
         NSString *decodeStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         
         decodeStr = [CodeWithDES decodeWithStr:decodeStr] ;
         NSLog(@"decodeStr:%@",decodeStr) ;
         NSData *decodeData = [decodeStr dataUsingEncoding:NSUTF8StringEncoding] ;
         id result = [NSJSONSerialization JSONObjectWithData:decodeData options:NSJSONReadingMutableContainers error:nil] ;
         //获取字典中的值
         if ([result isKindOfClass:[NSDictionary class]])
         {
             NSDictionary *dic = result ;
             NSLog(@"通知:%@",dic) ;
             if ([dic[@"status"]integerValue] == 1) {
                 [self downloadDetail] ;
             }
             else{
                 UIButton *errorbtn = [[UIButton alloc] initWithFrame:CGRectMake((__kScreenWidth - 100)/2, __kScreenHeight - 80, 100, 50)] ;
                 [errorbtn setTitle:@"工单操作失败" forState:UIControlStateNormal] ;
                 errorbtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:14.0f] ;
                 errorbtn.layer.cornerRadius = 10 ;
                 errorbtn.backgroundColor = [UIColor blackColor] ;
                 errorbtn.alpha = 0.8 ;
                 [[UIApplication sharedApplication].keyWindow addSubview:errorbtn] ;
                 [self performSelector:@selector(clearbtn:) withObject:errorbtn afterDelay:2.0] ;
             }
         }
     }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         [hud hideAnimated:YES] ;
         NSLog(@"Error: %@", error);
     }];
    
    
}


- (void)clearbtn:(id)sender
{
    [sender removeFromSuperview] ;
}


- (void)createView
{
    [ScrollView removeFromSuperview] ;
    
    ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, __kScreenWidth, self.view.frame.size.height)] ;
    ScrollView.backgroundColor = [UIColor whiteColor] ;
    ScrollView.showsVerticalScrollIndicator = NO ;
    ScrollView.bounces = NO ;
    ScrollView.userInteractionEnabled = YES ;
    [self.view addSubview:ScrollView] ;
    
    UIImageView *line1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, __kScreenWidth, 2)] ;
    [line1 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    [ScrollView addSubview:line1] ;
    
    UIImageView *line2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, line1.frame.origin.x + line1.frame.size.height + 40, __kScreenWidth - 20, 1)] ;
    [line2 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    [ScrollView addSubview:line2] ;
    
    UIImageView *line4 = [[UIImageView alloc] init] ;
    //显示工单流程图的背景view
    gdimageView = [[UIView alloc] init] ;
    if ([detailModel.gdstatus integerValue] < 9 || [detailModel.gdstatus integerValue] == 14 || [detailModel.gdstatus integerValue] == 15 || [detailModel.gdstatus integerValue] == 20) {
        
        UIImageView *line3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 90, __kScreenWidth , 7)] ;
        [line3 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
        gdimageView.frame = CGRectMake(0, 43, __kScreenWidth, 97) ;
        [gdimageView addSubview:line3] ;
        [ScrollView addSubview:gdimageView] ;
        line4.frame = CGRectMake(10, gdimageView.frame.origin.y + gdimageView.frame.size.height+ 80, __kScreenWidth - 20, 1) ;
        gdDoneView = [[UIView alloc] initWithFrame:CGRectMake(0, line4.frame.origin.y - 80, __kScreenWidth, 80)] ;
    }
    else
    {
        gdimageView.frame = CGRectMake(0, 43, __kScreenWidth, 0) ;
        line4.frame = CGRectMake(10, gdimageView.frame.origin.y + gdimageView.frame.size.height+ 60, __kScreenWidth - 20, 1) ;
        gdDoneView = [[UIView alloc] initWithFrame:CGRectMake(0, line4.frame.origin.y - 60, __kScreenWidth, 60)] ;
    }
    
    [line4 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    [ScrollView addSubview:line4] ;
    
    [ScrollView addSubview:gdDoneView] ;
    
    //订单号
    UILabel *gdId = [self creatlabel:16.0f color:[UIColor grayColor] alignment:NSTextAlignmentLeft] ;
    gdId.text = [NSString stringWithFormat:@"订单号：%@",detailModel.orderid] ;
    gdId.frame = CGRectMake(12, line4.frame.origin.y + line4.frame.size.height + 13, __kScreenWidth, 18.0f) ;
    [ScrollView addSubview:gdId] ;
    
    UIImageView *line5 = [[UIImageView alloc] initWithFrame:CGRectMake(10, line4.frame.origin.y + line4.frame.size.height + 40, __kScreenWidth - 20, 1)] ;
    [line5 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    [ScrollView addSubview:line5] ;
    
    //客户信息图片
    UIImageView *addressImage = [[UIImageView alloc] initWithFrame:CGRectMake(12, line5.frame.origin.y + line5.frame.size.height + 9, 39, 52)] ;
    [addressImage setImage:[UIImage imageNamed:@"order_details_location_icon"]] ;
    [ScrollView addSubview:addressImage] ;
    
    //客户姓名
    UILabel *consumerLabel = [self creatlabel:14.0f color:[UIColor darkGrayColor] alignment:NSTextAlignmentLeft] ;
    consumerLabel.text = @"安装客户：" ;
    CGSize consumerLength = [self lengthwithLabel:consumerLabel withsize:14.0f] ;
    consumerLabel.frame = CGRectMake(60, line5.frame.origin.y + line5.frame.size.height + 14, consumerLength.width, 16.0f) ;
    [ScrollView addSubview:consumerLabel] ;
    
    UILabel *cNameLabel = [self creatlabel:14.0f color:[UIColor blackColor] alignment:NSTextAlignmentLeft] ;
    cNameLabel.text = detailModel.consumername ;
    cNameLabel.frame = CGRectMake(60 + consumerLength.width, consumerLabel.frame.origin.y, __kScreenWidth, 16.0f) ;
    [ScrollView addSubview:cNameLabel] ;
    
    UILabel *addressLabel = [self creatlabel:14.0f color:[UIColor darkGrayColor] alignment:NSTextAlignmentLeft] ;
    addressLabel.numberOfLines = 0 ;
    addressLabel.textAlignment = NSTextAlignmentLeft ;
    addressLabel.text = [NSString stringWithFormat:@"%@ %@ %@ %@",detailModel.location1,detailModel.location2,detailModel.location3,detailModel.consumeraddress] ;
    addressLabel.frame = CGRectMake(60, consumerLabel.frame.origin.y + consumerLabel.frame.size.height + 4, __kScreenWidth - 130, 30.0f) ;
    [ScrollView addSubview:addressLabel] ;
    
    //拨号图片
    UIButton *phoneBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    phoneBtn.frame = CGRectMake(__kScreenWidth - 60, line5.frame.origin.y + line5.frame.size.height + 10, 50, 50) ;
    [phoneBtn setImage:[UIImage imageNamed:@"order_details_telephone_normal_icon.png"] forState:UIControlStateNormal] ;
    [phoneBtn addTarget:self action:@selector(CallPhone) forControlEvents:UIControlEventTouchUpInside] ;
    [ScrollView addSubview:phoneBtn] ;
    
    UIImageView *line6 = [[UIImageView alloc] initWithFrame:CGRectMake(10, line5.frame.origin.y + line5.frame.size.height+ 70, __kScreenWidth - 20, 1)] ;
    [line6 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    [ScrollView addSubview:line6] ;
    //表头-合计
    [self createListTitle:line6.frame] ;
    
    UIImageView *line7 = [[UIImageView alloc] initWithFrame:CGRectMake(10, line6.frame.origin.y + line6.frame.size.height + 20, __kScreenWidth - 20, 1)] ;
    [line7 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    [ScrollView addSubview:line7] ;
    UITableView *serviceListTableview = [[UITableView alloc] initWithFrame:CGRectMake(0, line7.frame.origin.y + line7.frame.size.height, __kScreenWidth, 21 * detailModel.serviceArray.count) style:UITableViewStylePlain] ;
    serviceListTableview.delegate = self ;
    serviceListTableview.dataSource = self ;
    serviceListTableview.scrollEnabled = NO ;
    serviceListTableview.separatorStyle = UITableViewCellSeparatorStyleNone ;
    serviceListTableview.showsVerticalScrollIndicator = NO;
    [ScrollView addSubview:serviceListTableview] ;
    
    UIImageView *line8 = [[UIImageView alloc] initWithFrame:CGRectMake(0, serviceListTableview.frame.origin.y + serviceListTableview.frame.size.height + 5, __kScreenWidth , 7)] ;
    [line8 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    [ScrollView addSubview:line8] ;
    
    picfirstArray = [NSMutableArray array] ;
    piclaterArray = [NSMutableArray array] ;
    
    if (detailModel.pictureArray.count != 0) {
        for (NSDictionary *dic in detailModel.pictureArray) {
            PicModel *model = [[PicModel alloc] init] ;
            [model setValuesForKeysWithDictionary:dic] ;
            if ([model.pictype integerValue] == 1) {
                [piclaterArray addObject:model] ;
            }
            else
            {
                [picfirstArray addObject:model] ;
            }
        }

    }
    
    NSLog(@"pictureArray12====%lu, %lu",(unsigned long)picfirstArray.count,(unsigned long)piclaterArray.count) ;
    UIImageView *line9 = [[UIImageView alloc] initWithFrame:CGRectMake(10, line8.frame.origin.y + line8.frame.size.height + 30, __kScreenWidth - 20, 1)] ;
    [line9 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    [ScrollView addSubview:line9] ;
    
    CGFloat lineHight = (__kScreenWidth - 60) / 3 * 0.8 ;
    
    UIImageView *line10 = [[UIImageView alloc] initWithFrame:CGRectMake(10, line9.frame.origin.y + line9.frame.size.height + lineHight + 20, __kScreenWidth - 20, 1)] ;
    [line10 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    
    UIImageView *line11 = [[UIImageView alloc] init] ;
    [line11 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    
    UIImageView *line12 = [[UIImageView alloc] init] ;
    [line12 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    
    if (picfirstArray.count == 0) {
        line10.frame = line9.frame;
    }
    else
    {
        CGFloat lineX = (__kScreenWidth - 20) / 3 ;
        UIImageView *lineleft = [[UIImageView alloc] initWithFrame:CGRectMake(9 + lineX, line9.frame.origin.y + line9.frame.size.height + 12, 1, lineHight - 4)] ;
        UIImageView *lineright = [[UIImageView alloc] initWithFrame:CGRectMake(10 + lineX * 2, line9.frame.origin.y + line9.frame.size.height + 12, 1, lineHight - 4)] ;
        [lineleft setImage:[UIImage imageNamed:@"password_alter_auth_code_divide_line.png"]] ;
        [lineright setImage:[UIImage imageNamed:@"password_alter_auth_code_divide_line.png"]] ;
        [ScrollView addSubview:lineleft] ;
        [ScrollView addSubview:lineright] ;
        
        [self initpicWithFrame:line9.frame inArray:picfirstArray] ;
    }
    if (piclaterArray.count == 0) {
        line11.frame = line10.frame ;
        line12.frame = CGRectMake(0, line11.frame.origin.y + line11.frame.size.height + 30, __kScreenWidth, 7) ;
    }
    else
    {
        line11.frame = CGRectMake(10, line10.frame.origin.y + line10.frame.size.height + 30, __kScreenWidth - 20, 1) ;
        line12.frame = CGRectMake(0, line11.frame.origin.y + line11.frame.size.height + lineHight + 20, __kScreenWidth, 7) ;
        
        CGFloat lineX = __kScreenWidth / 3 ;
        UIImageView *lineleft = [[UIImageView alloc] initWithFrame:CGRectMake(lineX, line11.frame.origin.y + line11.frame.size.height + 12, 1, lineHight - 4)] ;
        UIImageView *lineright = [[UIImageView alloc] initWithFrame:CGRectMake(lineX * 2, line11.frame.origin.y + line11.frame.size.height + 12, 1, lineHight - 4)] ;
        [lineleft setImage:[UIImage imageNamed:@"password_alter_auth_code_divide_line.png"]] ;
        [lineright setImage:[UIImage imageNamed:@"password_alter_auth_code_divide_line.png"]] ;
        [ScrollView addSubview:lineleft] ;
        [ScrollView addSubview:lineright] ;
        
        [self initpicWithFrame:line11.frame inArray:piclaterArray] ;
    }
    [ScrollView addSubview:line10] ;
    [ScrollView addSubview:line11] ;
    [ScrollView addSubview:line12] ;
    
    //安装前label
    UILabel *picfirstLabel = [self creatlabel:16.0f color:[UIColor blackColor] alignment:NSTextAlignmentLeft] ;
    picfirstLabel.text = @"安装前图片" ;
    picfirstLabel.frame = CGRectMake(12, line8.frame.origin.y + line8.frame.size.height + 7, __kScreenWidth, 18.0f) ;
    [ScrollView addSubview:picfirstLabel] ;
    
    //安装后label
    UILabel *piclasterLabel = [self creatlabel:16.0f color:[UIColor blackColor] alignment:NSTextAlignmentLeft] ;
    piclasterLabel.text = @"安装后图片" ;
    piclasterLabel.frame = CGRectMake(12, line10.frame.origin.y + line10.frame.size.height + 7, __kScreenWidth, 18.0f) ;
    [ScrollView addSubview:piclasterLabel] ;
    
    //建单时间
    UILabel *setListTimeLabel = [self creatlabel:14.0f color:[UIColor darkGrayColor] alignment:NSTextAlignmentLeft] ;
    setListTimeLabel.text = [NSString stringWithFormat:@"建单时间：%@",detailModel.inputdatetime] ;
    setListTimeLabel.frame = CGRectMake(12, line12.frame.origin.y + line12.frame.size.height + 14, __kScreenWidth, 16.0f) ;
    //接单时间
    UILabel *acceptListTimeLabel = [self creatlabel:14.0f color:[UIColor darkGrayColor] alignment:NSTextAlignmentLeft] ;
    acceptListTimeLabel.text = [NSString stringWithFormat:@"接单时间：%@",detailModel.servicedatetime] ;
    if ([detailModel.gdstatus integerValue] == 3) {
        acceptListTimeLabel.frame = setListTimeLabel.frame ;
    }
    else{
        acceptListTimeLabel.frame = CGRectMake(12, setListTimeLabel.frame.origin.y + setListTimeLabel.frame.size.height + 4, __kScreenWidth, 16.0f) ;
        [ScrollView addSubview:acceptListTimeLabel] ;
    }
    [ScrollView addSubview:setListTimeLabel] ;
    
    UIImageView *line13 = [[UIImageView alloc] initWithFrame:CGRectMake(10, acceptListTimeLabel.frame.origin.y + acceptListTimeLabel.frame.size.height + 14, __kScreenWidth - 20, 1)] ;
    [line13 setImage:[UIImage imageNamed:@"layout_small_line_bg.png"]] ;
    [ScrollView addSubview:line13] ;
    
    ScrollView.contentSize = CGSizeMake(0, line13.frame.origin.y + line13.frame.size.height + 100) ;
    
    //历时几天
    UILabel *lishiLabel = [self creatlabel:14.0f color:[UIColor grayColor] alignment:NSTextAlignmentLeft] ;
    lishiLabel.text = [NSString stringWithFormat:@"历时：%@天",detailModel.gdprogress] ;
    CGSize lishilength = [self lengthwithLabel:lishiLabel withsize:14.0f] ;
    lishiLabel.frame = CGRectMake(12, 14, lishilength.width, 16.0f) ;
    [ScrollView addSubview:lishiLabel] ;
    
    if ([detailModel.gdstatus integerValue] > 4) {
        UILabel *yuyueTimeLabel = [self creatlabel:14.0f color:[UIColor grayColor] alignment:NSTextAlignmentCenter] ;
        NSString *begin = [detailModel.servicedatetimebegin substringWithRange:NSMakeRange(detailModel.servicedatetimebegin.length - 8, 5)] ;
        NSString *end = [detailModel.servicedatetimeend substringWithRange:NSMakeRange(detailModel.servicedatetimebegin.length - 8, 5)] ;
        NSString *day = [detailModel.servicedatetimebegin substringWithRange:NSMakeRange(5, 5)] ;
        NSString *time = [NSString stringWithFormat:@"预约时间：%@ %@~%@",day,begin,end] ;
        yuyueTimeLabel.text = time ;
        yuyueTimeLabel.frame = CGRectMake(lishiLabel.frame.origin.x + lishiLabel.frame.size.width, 14, __kScreenWidth - (lishiLabel.frame.origin.x + lishiLabel.frame.size.width), 16.0f) ;
        [ScrollView addSubview:yuyueTimeLabel] ;
    }
    [self createGdImage:[detailModel.gdstatus integerValue]] ;
    [self createDoneView] ;
    
}

#pragma mark - 创建图片
- (void)initpicWithFrame:(CGRect)frame inArray:(NSArray *)array
{
    imageUrlArray = [NSMutableArray array] ;
    [imageUrlArray removeAllObjects] ;
    CGFloat imageSize = (__kScreenWidth - 60) / 3 ;
    for (NSInteger i = 0; i < array.count; i++) {
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(10 + (imageSize + 20) * i, frame.origin.y + frame.size.height + 10, imageSize, imageSize * 0.8)] ;
        image.layer.cornerRadius = 5.0f ;
        image.layer.masksToBounds = YES ;
        PicModel *model = array[i] ;
        NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat: @"%@%@",model.picpath,model.picname]] ;
        [imageUrlArray addObject:[NSString stringWithFormat: @"%@%@",model.picpath,model.picname]] ;
        
        [image sd_setImageWithURL:imageUrl] ;

        image.userInteractionEnabled = YES ;
        
        image.tag = i ;
        
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(previewImage:)];
        tapGestureRecognizer.numberOfTapsRequired = 1;
        [image addGestureRecognizer:tapGestureRecognizer];
        
//        image.userInteractionEnabled = YES ;
//        
//        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(uploadPic)];
//        tapGestureRecognizer.numberOfTapsRequired = 1;
//        [image addGestureRecognizer: tapGestureRecognizer];
        
        [ScrollView addSubview:image] ;
        
        if ([detailModel.gdstatus integerValue] == 20){
            UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
            deleteBtn.frame = CGRectMake(imageSize - 22, 2, 20, 20) ;
            [deleteBtn setImage:[UIImage imageNamed:@"set_service_time_close_press_btn.png"] forState:UIControlStateNormal] ;
            [image addSubview:deleteBtn] ;
            deleteBtn.tag = i ;
            [deleteBtn addTarget:self action:@selector(deletePic:) forControlEvents:UIControlEventTouchUpInside] ;
        
        }
    }
    if ([detailModel.gdstatus integerValue] == 20) {
        noimageCount = 3 - array.count ;
        for (NSInteger i = 0; i < noimageCount; i ++) {
            UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(10 + (imageSize + 20) * (array.count + i), frame.origin.y + frame.size.height + 10, imageSize, imageSize * 0.8)] ;
            image.layer.cornerRadius = 5.0f ;
            image.layer.masksToBounds = YES ;
            [image setImage:[UIImage imageNamed:@"order_details_add_image_btn.png"]] ;
            [ScrollView addSubview:image] ;
            
            image.userInteractionEnabled = YES ;
            
            UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(uploadPic)];
            tapGestureRecognizer.numberOfTapsRequired = 1;
            [image addGestureRecognizer: tapGestureRecognizer];
        }
    }
}

#pragma mark - 创建表单表头
- (void)createListTitle:(CGRect)frame
{
    CGFloat labelwidth = __kScreenWidth / 4 ;
    UILabel *hejiLable = [self creatlabel:14.0f color:[UIColor blackColor] alignment:NSTextAlignmentLeft] ;
    hejiLable.text = @"   合计" ;
    hejiLable.frame = CGRectMake(0, frame.origin.y + frame.size.height + 3, labelwidth, 16.0f) ;
    [ScrollView addSubview:hejiLable] ;
    
    UILabel *serviceLabel = [self creatlabel:14.0f color:[UIColor blackColor] alignment:NSTextAlignmentCenter] ;
    serviceLabel.text = @"服务" ;
    serviceLabel.frame = CGRectMake(labelwidth, frame.origin.y + frame.size.height + 3, labelwidth, 16.0f) ;
    [ScrollView addSubview:serviceLabel] ;
    
    UILabel *numLabel = [self creatlabel:14.0f color:[UIColor blackColor] alignment:NSTextAlignmentCenter] ;
    numLabel.text = [NSString stringWithFormat:@"%lu件",(unsigned long)detailModel.serviceArray.count] ;
    numLabel.frame = CGRectMake(labelwidth*2, frame.origin.y + frame.size.height + 3, labelwidth, 16.0f) ;
    [ScrollView addSubview:numLabel] ;
    
    UILabel *priceLabel = [self creatlabel:14.0f color:[UIColor blackColor] alignment:NSTextAlignmentLeft] ;
    priceLabel.text = [NSString stringWithFormat:@"￥%@",self.serviceAmount] ;
    priceLabel.frame = CGRectMake(labelwidth*3, frame.origin.y + frame.size.height + 3, labelwidth, 16.0f) ;
    [ScrollView addSubview:priceLabel] ;
}

#pragma mark - tableviewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1 ;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"tableview  serviceArray:%lu",(unsigned long)serviceArray.count) ;
//    return detailModel.serviceArray.count ;
    return serviceArray.count ;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ServiceListTableViewCell *cell = [ServiceListTableViewCell cellWithTableView:tableView] ;
    cell.selectionStyle = UITableViewCellSelectionStyleNone ;
    
    if (indexPath.row == serviceArray.count - 1) {
        [cell.lineView removeFromSuperview] ;
    }
    
    DetailSheetModle *model = serviceArray[indexPath.row] ;
    NSLog(@"%lu",(unsigned long)serviceArray.count) ;
    [cell config:model] ;
    
    return cell ;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 21 ;
}


//工单流程图
- (void)createGdImage:(NSInteger) statusid
{
    CGFloat Btnsize = (__kScreenWidth - 20) / 8 ;
    CGFloat leftlength = Btnsize / 2 + 10 ;
    CGFloat uplength = 90 - Btnsize - 34 ;
    CGFloat lineHeight = uplength + Btnsize / 2 - Btnsize * 7 / 60.0f ;
    UIImage *grayIamge = [UIImage imageNamed:@"order_details_status_black_icon.png"] ;
    UIImage *blueIamge = [UIImage imageNamed:@"order_details_status_light_icon.png"] ;
    UIImage *lineImage = [UIImage imageNamed:@"order_details_status_line.png"] ;
    UIImage *arrowImage = [UIImage imageNamed:@"order_details_status_arrows.png"] ;
    
    UIButton *jiedanBtn = [self creteBtn:@"接单" forState:UIControlStateDisabled] ;
    UIButton *yuyueBtn = [self creteBtn:@"预约" forState:UIControlStateDisabled] ;
    UIButton *shangmenBtn = [self creteBtn:@"上门" forState:UIControlStateDisabled] ;
    UIButton *pingjiaBtn = [self creteBtn:@"评价" forState:UIControlStateDisabled] ;
    
    jiedanBtn.frame = CGRectMake(leftlength - 3, uplength, Btnsize, Btnsize) ;
    yuyueBtn.frame = CGRectMake(leftlength + Btnsize * 2 - 1, uplength, Btnsize, Btnsize) ;
    shangmenBtn.frame = CGRectMake(leftlength + Btnsize * 4 + 1, uplength, Btnsize, Btnsize) ;
    pingjiaBtn.frame = CGRectMake(leftlength + Btnsize * 6 + 3, uplength, Btnsize, Btnsize) ;
    
    UIImageView *line1 = [[UIImageView alloc] initWithFrame:CGRectMake(leftlength + Btnsize, uplength + Btnsize / 2 - 0.5, Btnsize, Btnsize * 14 / 60.0f)] ;
    UIImageView *line2 = [[UIImageView alloc] initWithFrame:CGRectMake(leftlength + Btnsize * 3, uplength + Btnsize / 2 - 0.5, Btnsize, 1)] ;
    UIImageView *line3 = [[UIImageView alloc] initWithFrame:CGRectMake(leftlength + Btnsize * 5, uplength + Btnsize / 2 - 0.5, Btnsize, 1)] ;
    
    UILabel *downLabel = [self creatlabel:14.0f color:[UIColor blackColor] alignment:NSTextAlignmentLeft] ;
    downLabel.frame = CGRectMake(12, 66, __kScreenWidth, 16.0f) ;
    [gdimageView addSubview:downLabel] ;
                                                                     
    if (statusid == 3) {
        [jiedanBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [yuyueBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [shangmenBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [pingjiaBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [line1 setImage:lineImage] ;
        [line2 setImage:lineImage] ;
        [line3 setImage:lineImage] ;
        line1.frame = CGRectMake(leftlength + Btnsize - 2, uplength + Btnsize / 2 - 0.5, Btnsize, 1) ;
        line2.frame = CGRectMake(leftlength + Btnsize * 3, uplength + Btnsize / 2 - 0.5, Btnsize, 1) ;
        line3.frame = CGRectMake(leftlength + Btnsize * 5 + 2, uplength + Btnsize / 2 - 0.5, Btnsize, 1) ;
        downLabel.text = @"订单未接单，请尽快接单" ;
    }
    else if (statusid == 4)
    {
        [jiedanBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [yuyueBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [shangmenBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [pingjiaBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [line1 setImage:arrowImage] ;
        [line2 setImage:lineImage] ;
        [line3 setImage:lineImage] ;
        line1.frame = CGRectMake(leftlength + Btnsize - 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line2.frame = CGRectMake(leftlength + Btnsize * 3, uplength + Btnsize / 2 - 0.5, Btnsize, 1) ;
        line3.frame = CGRectMake(leftlength + Btnsize * 5 + 2, uplength + Btnsize / 2 - 0.5, Btnsize, 1) ;
        downLabel.text = @"您已接单，请尽快预约客户" ;
    }
    else if (statusid == 5)
    {
        [jiedanBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [yuyueBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [shangmenBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [pingjiaBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [line1 setImage:arrowImage] ;
        [line2 setImage:arrowImage] ;
        [line3 setImage:lineImage] ;
        line1.frame = CGRectMake(leftlength + Btnsize - 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line2.frame = CGRectMake(leftlength + Btnsize * 3, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line3.frame = CGRectMake(leftlength + Btnsize * 5 + 2, uplength + Btnsize / 2 - 0.5, Btnsize, 1) ;
        downLabel.text = @"您已预约客户，请按时服务，或者跟客户改约时间" ;
    }
    else if (statusid == 6)
    {
        [jiedanBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [yuyueBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [shangmenBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [pingjiaBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [line1 setImage:arrowImage] ;
        [line2 setImage:arrowImage] ;
        [line3 setImage:arrowImage] ;
        line1.frame = CGRectMake(leftlength + Btnsize - 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line2.frame = CGRectMake(leftlength + Btnsize * 3, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line3.frame = CGRectMake(leftlength + Btnsize * 5 + 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        downLabel.text = @"开工了，记得索要评价代码" ;
    }
    else if (statusid == 7)
    {
        [jiedanBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [yuyueBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [shangmenBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [pingjiaBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [line1 setImage:arrowImage] ;
        [line2 setImage:arrowImage] ;
        [line3 setImage:arrowImage] ;
        line1.frame = CGRectMake(leftlength + Btnsize - 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line2.frame = CGRectMake(leftlength + Btnsize * 3, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line3.frame = CGRectMake(leftlength + Btnsize * 5 + 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        downLabel.text = @"开工了，记得索要评价代码" ;
    }
    else if (statusid == 14)
    {
        [jiedanBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [yuyueBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [shangmenBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [pingjiaBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [line1 setImage:arrowImage] ;
        [line2 setImage:arrowImage] ;
        [line3 setImage:arrowImage] ;
        line1.frame = CGRectMake(leftlength + Btnsize - 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line2.frame = CGRectMake(leftlength + Btnsize * 3, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line3.frame = CGRectMake(leftlength + Btnsize * 5 + 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        downLabel.text = @"开工了，记得索要评价代码" ;
    }
    else if (statusid == 15)
    {
        [jiedanBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [yuyueBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [shangmenBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [pingjiaBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [line1 setImage:arrowImage] ;
        [line2 setImage:arrowImage] ;
        [line3 setImage:arrowImage] ;
        line1.frame = CGRectMake(leftlength + Btnsize - 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line2.frame = CGRectMake(leftlength + Btnsize * 3, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line3.frame = CGRectMake(leftlength + Btnsize * 5 + 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        downLabel.text = @"您辛苦了，不要忘了上传完工照片" ;
    }
    else if (statusid == 20)
    {
        [jiedanBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [yuyueBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [shangmenBtn setBackgroundImage:blueIamge forState:UIControlStateDisabled] ;
        [pingjiaBtn setBackgroundImage:grayIamge forState:UIControlStateDisabled] ;
        [line1 setImage:arrowImage] ;
        [line2 setImage:arrowImage] ;
        [line3 setImage:arrowImage] ;
        line1.frame = CGRectMake(leftlength + Btnsize - 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line2.frame = CGRectMake(leftlength + Btnsize * 3, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        line3.frame = CGRectMake(leftlength + Btnsize * 5 + 2, lineHeight, Btnsize, Btnsize * 14 / 60.0f) ;
        downLabel.text = @"图片已上传，请修改图片或确认完工" ;
    }


    
    [gdimageView addSubview:jiedanBtn] ;
    [gdimageView addSubview:yuyueBtn] ;
    [gdimageView addSubview:shangmenBtn] ;
    [gdimageView addSubview:pingjiaBtn] ;
    [gdimageView addSubview:line1] ;
    [gdimageView addSubview:line2] ;
    [gdimageView addSubview:line3] ;
}

//工单操作view
- (void)createDoneView
{
    NSInteger statusId =  [detailModel.gdstatus integerValue] ;
    if (statusId == 3) {
        UIButton *refuseBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
        [refuseBtn setTitle:@"拒单" forState:UIControlStateNormal] ;
        [refuseBtn setBackgroundImage:[UIImage imageNamed:@"button_refuse_normal_bg.png"] forState:UIControlStateNormal] ;
        refuseBtn.frame = CGRectMake(15, 15, (__kScreenWidth - 40) / 2, 50) ;
        [refuseBtn addTarget:self action:@selector(refuseSheet) forControlEvents:UIControlEventTouchUpInside] ;
        refuseBtn.layer.masksToBounds = YES ;
        
        [gdDoneView addSubview:refuseBtn] ;
        
        UIButton *normalBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
        [normalBtn setTitle:@"接单" forState:UIControlStateNormal] ;
        [normalBtn setBackgroundImage:[UIImage imageNamed:@"button_normal_bg.png"] forState:UIControlStateNormal] ;
        normalBtn.frame = CGRectMake(refuseBtn.frame.origin.x + refuseBtn.frame.size.width + 10, 15, (__kScreenWidth - 40) / 2, 50) ;
        
        [normalBtn addTarget:self action:@selector(acceptSheet) forControlEvents:UIControlEventTouchUpInside] ;
        
        normalBtn.layer.masksToBounds = YES ;
        [gdDoneView addSubview:normalBtn] ;
    } 
    if (statusId == 4) {
        UIButton *yuyueBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
        [yuyueBtn setTitle:@"预约时间" forState:UIControlStateNormal] ;
        [yuyueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
        yuyueBtn.frame = CGRectMake(__kScreenWidth / 4, 15, __kScreenWidth/2, 50) ;
        yuyueBtn.layer.cornerRadius = 5.0f ;
        yuyueBtn.backgroundColor = [UIColor blueColor] ;
        [yuyueBtn addTarget:self action:@selector(order) forControlEvents:UIControlEventTouchUpInside] ;
        [gdDoneView addSubview:yuyueBtn] ;
    }
    if (statusId == 5) {
        UIButton *anzhaungBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
        [anzhaungBtn setTitle:@"上门安装" forState:UIControlStateNormal] ;
        [anzhaungBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
        anzhaungBtn.frame = CGRectMake(__kScreenWidth / 4, 15, __kScreenWidth/2, 50) ;
        anzhaungBtn.layer.cornerRadius = 5.0f ;
        anzhaungBtn.backgroundColor = [UIColor blueColor] ;
        [anzhaungBtn addTarget:self action:@selector(doorAnZhuang) forControlEvents:UIControlEventTouchUpInside] ;
        [gdDoneView addSubview:anzhaungBtn] ;
    }
    if (statusId == 6) {
        field = [self createTextfield:@"输入上门验证码" frame:CGRectMake(__kScreenWidth / 8, 20, __kScreenWidth/2, 40) alignment:NSTextAlignmentCenter] ;
        
        UIButton *querenBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
        [querenBtn setTitle:@"确认" forState:UIControlStateNormal] ;
        [querenBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
        querenBtn.frame = CGRectMake(field.frame.origin.x + field.frame.size.width + 10, 15, __kScreenWidth/4, 50) ;
        querenBtn.layer.cornerRadius = 5.0f ;
        querenBtn.backgroundColor = [UIColor blueColor] ;
        [querenBtn addTarget:self action:@selector(downloadOfDoorYz) forControlEvents:UIControlEventTouchUpInside] ;
        [gdDoneView addSubview:field] ;
        [gdDoneView addSubview:querenBtn] ;

    }
    if (statusId == 7) {
        field = [self createTextfield:@"输入完工验证码" frame:CGRectMake(__kScreenWidth / 8, 20, __kScreenWidth/2, 40) alignment:NSTextAlignmentCenter] ;
        
        UIButton *querenBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
        [querenBtn setTitle:@"确认" forState:UIControlStateNormal] ;
        [querenBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
        querenBtn.frame = CGRectMake(field.frame.origin.x + field.frame.size.width + 10, 15, __kScreenWidth/4, 50) ;
        querenBtn.layer.cornerRadius = 5.0f ;
        querenBtn.backgroundColor = [UIColor blueColor] ;
        [querenBtn addTarget:self action:@selector(downloadOfhaveDoneYz) forControlEvents:UIControlEventTouchUpInside] ;
        [gdDoneView addSubview:field] ;
        [gdDoneView addSubview:querenBtn] ;
    }
    
    if (statusId == 9) {
        UILabel *havedoneLabel = [self creatlabel:24.0f color:[UIColor blackColor] alignment:NSTextAlignmentCenter] ;
        havedoneLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:24.0f] ;
        havedoneLabel.text = @"工单已完成，继续努力哦!" ;
        havedoneLabel.frame = CGRectMake(0, 17, __kScreenWidth, 26.0f) ;
        [gdDoneView addSubview:havedoneLabel] ;
    }
    if (statusId == 10 || statusId == 11) {
        UILabel *havedoneLabel = [self creatlabel:24.0f color:[UIColor blackColor] alignment:NSTextAlignmentCenter] ;
        havedoneLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:24.0f] ;
        havedoneLabel.text = @"异常工单待处理中！" ;
        havedoneLabel.frame = CGRectMake(0, 17, __kScreenWidth, 26.0f) ;
        [gdDoneView addSubview:havedoneLabel] ;
    }
    if (statusId == 14) {
        UIButton *yuyueBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
        [yuyueBtn setTitle:@"完成工单" forState:UIControlStateNormal] ;
        [yuyueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
        yuyueBtn.frame = CGRectMake(__kScreenWidth / 4, 15, __kScreenWidth/2, 50) ;
        yuyueBtn.layer.cornerRadius = 5.0f ;
        yuyueBtn.backgroundColor = [UIColor blueColor] ;
        [yuyueBtn addTarget:self action:@selector(haveDoneGD) forControlEvents:UIControlEventTouchUpInside] ;
        [gdDoneView addSubview:yuyueBtn] ;
    }
    if (statusId == 15) {
        UIButton *yuyueBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
        [yuyueBtn setTitle:@"上传图片" forState:UIControlStateNormal] ;
        [yuyueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
        yuyueBtn.frame = CGRectMake(__kScreenWidth / 4, 15, __kScreenWidth/2, 50) ;
        yuyueBtn.layer.cornerRadius = 5.0f ;
        yuyueBtn.backgroundColor = [UIColor blueColor] ;
        
        noimageCount = 3 ;
        [yuyueBtn addTarget:self action:@selector(uploadPic) forControlEvents:UIControlEventTouchUpInside] ;

        [gdDoneView addSubview:yuyueBtn] ;
    }
    if (statusId == 20) {
        UIButton *yuyueBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
        [yuyueBtn setTitle:@"确认完工" forState:UIControlStateNormal] ;
        [yuyueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
        yuyueBtn.frame = CGRectMake(__kScreenWidth / 4, 15, __kScreenWidth/2, 50) ;
        yuyueBtn.layer.cornerRadius = 5.0f ;
        yuyueBtn.backgroundColor = [UIColor blueColor] ;
        [yuyueBtn addTarget:self action:@selector(downloadOfhaveDoneOfFinish) forControlEvents:UIControlEventTouchUpInside] ;
        [gdDoneView addSubview:yuyueBtn] ;
    }

    if (statusId == 21) {
        UILabel *havedoneLabel = [self creatlabel:24.0f color:[UIColor blackColor] alignment:NSTextAlignmentCenter] ;
        havedoneLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:24.0f] ;
        havedoneLabel.text = @"工单已在审核中，请稍等!" ;
        havedoneLabel.frame = CGRectMake(0, 17, __kScreenWidth, 26.0f) ;
        [gdDoneView addSubview:havedoneLabel] ;
    }
}

#pragma mark - 创建textfield
- (PasswordField *)createTextfield:(NSString *)title frame:(CGRect)frame alignment:(NSTextAlignment)alignment
{
    PasswordField *textfield = [[PasswordField alloc] initWithFrame:frame] ;
    textfield.placeholder = title ;
    textfield.delegate = self ;
    textfield.keyboardType = UIKeyboardTypeDefault ;
    textfield.backgroundColor=[UIColor whiteColor];
    textfield.layer.borderColor = [UIColor blackColor].CGColor ;
    textfield.layer.borderWidth = 1.0f ;
    textfield.layer.cornerRadius = 4.0f ;
    textfield.adjustsFontSizeToFitWidth=YES;//自适应宽度
    //设置UITextField的边框的风格
    textfield.borderStyle=UITextBorderStyleNone;
    textfield.textAlignment = alignment ;
    return textfield ;
}

//创建时间textfield
- (UITextField *)createDatefield:(CGRect)frame
{
    UITextField *textfield = [[UITextField alloc] initWithFrame:frame] ;
    textfield.delegate = self ;
    textfield.keyboardType = UIKeyboardTypeNumbersAndPunctuation ;
    textfield.backgroundColor=[UIColor whiteColor];
    //    textfield.layer.borderColor = [UIColor blackColor].CGColor ;
    //    textfield.layer.borderWidth = 1.0f ;
    //    textfield.layer.cornerRadius = 4.0f ;
    textfield.adjustsFontSizeToFitWidth=YES;//自适应宽度
    //设置UITextField的边框的风格
    textfield.borderStyle=UITextBorderStyleNone;
    textfield.textAlignment = NSTextAlignmentCenter ;
    return textfield ;
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder] ;
    return YES ;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if ([textField isEqual:yearfield] || [textField isEqual:monthfield] || [textField isEqual:dayfield]) {
        NSInteger year = [yearfield.text integerValue] ;
        NSInteger month = [monthfield.text integerValue] ;
        NSInteger day = [dayfield.text integerValue] ;
        
        if (year < 1900 || year > 2100) {
            NSDate *currentDate = [NSDate date];//获取当前时间，日期
            NSDateFormatter *yearFormatter = [[NSDateFormatter alloc] init];
            [yearFormatter setDateFormat:@"YYYY"];
            NSString *yearString = [yearFormatter stringFromDate:currentDate];
            yearfield.text = yearString ;
        }
        
        if (month < 1 ) {
            monthfield.text = @"12" ;
            yearfield.text = [NSString stringWithFormat:@"%ld",year-1] ;
            [self textFieldDidEndEditing:yearfield] ;
        }
        else if (month > 12) {
            monthfield.text = @"01" ;
            yearfield.text = [NSString stringWithFormat:@"%ld",year+1] ;
            [self textFieldDidEndEditing:yearfield] ;
        }
        
        
        if ((month==1 || month==2 || month==4 || month== 6 || month == 8 || month == 9 || month == 11) && day < 1 ) {
            dayfield.text = @"31" ;
            monthfield.text = [NSString stringWithFormat:@"%ld",month-1] ;
            [self textFieldDidEndEditing:monthfield] ;
        }
        else if ((month==1 || month==3 || month==5 || month== 7 || month == 8 || month == 10 || month == 12) && day > 31 ){
            dayfield.text = @"01" ;
            monthfield.text = [NSString stringWithFormat:@"%ld",month+1] ;
            [self textFieldDidEndEditing:monthfield] ;
        }
        else if ((month==5 || month==7 || month==10 || month== 12) && day < 1){
            dayfield.text = @"30" ;
            monthfield.text = [NSString stringWithFormat:@"%ld",month-1] ;
            [self textFieldDidEndEditing:monthfield] ;
            
        }
        
        else if( (month==4 || month==6 || month==9 || month== 11)&& (day > 30) ){
            dayfield.text = @"01" ;
            monthfield.text = [NSString stringWithFormat:@"%ld",month+1] ;
            [self textFieldDidEndEditing:monthfield] ;
            
        }
        else if ((year % 400 == 0) && month == 3 && day < 1)
        {
            dayfield.text = @"29" ;
            monthfield.text = [NSString stringWithFormat:@"%ld",month-1] ;
            [self textFieldDidEndEditing:monthfield] ;
            
        }
        else if ((year % 400 == 0) && month == 2 && day > 29)
        {
            dayfield.text = @"01" ;
            monthfield.text = [NSString stringWithFormat:@"%ld",month+1] ;
            [self textFieldDidEndEditing:monthfield] ;
        }
        else if ((year % 400 != 0) && month == 3 && day < 1)
        {
            dayfield.text = @"28" ;
            monthfield.text = [NSString stringWithFormat:@"%ld",month-1] ;
            [self textFieldDidEndEditing:monthfield] ;
            
        }
        else if ((year % 400 != 0) && month == 2 && day > 28)
        {
            dayfield.text = @"01" ;
            monthfield.text = [NSString stringWithFormat:@"%ld",month+1] ;
            [self textFieldDidEndEditing:monthfield] ;
            
        }
        
    }
}


//创建btn
- (UIButton *)creteBtn:(NSString *)title forState:(UIControlState)state
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [btn setTitle:title forState:state] ;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
    btn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:14.0f] ;
    btn.enabled = NO ;
    return btn ;
}

//创建label
- (UILabel *)creatlabel:(CGFloat) size color:(UIColor *)color alignment:(NSTextAlignment) alignment
{
    UILabel *label = [[UILabel alloc] init] ;
    label.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:size] ;
    label.backgroundColor = [UIColor clearColor] ;
    label.textAlignment = alignment ;
    label.textColor = color ;
    return label ;
}

- (CGSize)lengthwithLabel:(UILabel *)lable withsize:(CGFloat) size
{
    NSDictionary *attribute1 = @{NSFontAttributeName: [UIFont fontWithName:@"AvenirLTStd-Light" size:size]};
    CGSize DescSize = [lable.text boundingRectWithSize:CGSizeMake(MAXFLOAT, size) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute1 context:nil].size;
    return DescSize ;
}

#pragma mark - 工单按钮点击操作
//拨号
-(void)CallPhone{
    NSString *phoneNum = detailModel.consumercontact1;// 电话号码
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];
    if ( !phoneCallWebView ) {
        phoneCallWebView = [[UIWebView alloc]initWithFrame:CGRectZero];// 这个webView只是一个后台的容易 不需要add到页面上来 效果跟方法二一样 但是这个方法是合法的
    }
    [phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];
}
//拒单
- (void)refuseSheet
{
    RefuseViewController *vc = [[RefuseViewController alloc] init] ;
    vc.ordid = detailModel.orderid ;
    self.hidesBottomBarWhenPushed = YES ;
    [self.navigationController pushViewController:vc animated:NO] ;
}
//接单
- (void)acceptSheet
{
    NSLog(@"接单") ;
    mainView = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.frame] ;
    mainView.backgroundColor = [UIColor blackColor] ;
    mainView.alpha = 0.8 ;
    [[UIApplication sharedApplication].keyWindow addSubview:mainView] ;
    alterview = [[UIView alloc] initWithFrame:CGRectMake(__kScreenWidth / 8, (__kScreenHeight *3/4 - 50) / 2, __kScreenWidth *3/4, __kScreenWidth/4+50)] ;
    alterview.backgroundColor = [UIColor whiteColor] ;
    alterview.layer.cornerRadius = 5.0f ;
    alterview.alpha = 1 ;
    [[UIApplication sharedApplication].keyWindow addSubview:alterview] ;
    
    UILabel *label = [[UILabel alloc] init] ;
    label.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:16.0f] ;
    label.backgroundColor = [UIColor clearColor] ;
    label.textAlignment = NSTextAlignmentLeft ;
    label.textColor = [UIColor grayColor] ;
    label.text = @"是否接单？" ;
    label.frame = CGRectMake(20, (alterview.frame.size.height - 60)/2, 150, 18.0f) ;
    [alterview addSubview:label] ;
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal] ;
    //cancelBtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:16.0f] ;
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
    [cancelBtn setBackgroundImage:[UIImage imageNamed:@"dialog_cancel_normal_btn_bg.png"] forState:UIControlStateNormal] ;
    cancelBtn.frame = CGRectMake(10, alterview.frame.size.height - 60, (alterview.frame.size.width - 40)/2, 40) ;
    [cancelBtn addTarget:self action:@selector(removeMainView) forControlEvents:UIControlEventTouchUpInside] ;
    [alterview addSubview:cancelBtn] ;
    
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [confirmBtn setTitle:@"确认" forState:UIControlStateNormal] ;
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
    [confirmBtn setBackgroundImage:[UIImage imageNamed:@"dialog_enter_normal_btn_bg.png"] forState:UIControlStateNormal] ;
    confirmBtn.frame = CGRectMake(cancelBtn.frame.origin.x + cancelBtn.frame.size.width + 20 , alterview.frame.size.height - 60, (alterview.frame.size.width - 40)/2, 40) ;
    [confirmBtn addTarget:self action:@selector(downloadOfJiedan) forControlEvents:UIControlEventTouchUpInside] ;
    [alterview addSubview:confirmBtn] ;
    
}


//预约时间操作
- (void)order
{
    NSLog(@"预约") ;
    mainView = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.frame] ;
    mainView.backgroundColor = [UIColor blackColor] ;
    mainView.alpha = 0.8 ;
    [[UIApplication sharedApplication].keyWindow addSubview:mainView] ;
    
    orderTimeBackView = [[UIImageView alloc] init] ;
    CGFloat heith = (__kScreenWidth - 20) * 700 / 640 ;
    orderTimeBackView.frame = CGRectMake(10, (__kScreenHeight - heith) / 2, __kScreenWidth - 20, heith) ;
    [orderTimeBackView setImage:[UIImage imageNamed:@"set_service_time_dialog_bg.png"]] ;
    orderTimeBackView.userInteractionEnabled = YES ;
    [[UIApplication sharedApplication].keyWindow addSubview:orderTimeBackView] ;
    
    UIButton *closebtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [closebtn setImage:[UIImage imageNamed:@"set_service_time_close_normal_btn.png"] forState:UIControlStateNormal] ;
    closebtn.frame = CGRectMake(6, 6, 24, 24) ;
    [closebtn addTarget:self action:@selector(removeMainView) forControlEvents:UIControlEventTouchUpInside] ;
    [orderTimeBackView addSubview:closebtn] ;
    
    UIImageView *verticalLine = [[UIImageView alloc] init] ;
    verticalLine.frame = CGRectMake(__kScreenWidth / 4, 32, 0.5, orderTimeBackView.frame.size.height - 80) ;
    [verticalLine setImage:[UIImage imageNamed:@"set_service_time_shu_divide_line"]] ;
    [orderTimeBackView addSubview:verticalLine] ;
    
    yearfield = [self createDatefield:CGRectMake(__kScreenWidth / 4 + 10, 54, 58, 34)] ;
    
    //    NSDate *GMTDate = [NSDate date];//获取当前时间，日期
    //    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    //    NSInteger interval = [zone secondsFromGMTForDate:GMTDate];
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    
    NSDateFormatter *yearFormatter = [[NSDateFormatter alloc] init];
    [yearFormatter setDateFormat:@"YYYY"];
    NSString *yearString = [yearFormatter stringFromDate:currentDate];
    yearfield.text = yearString ;
    [orderTimeBackView addSubview:yearfield] ;
    
    UIButton *jia1Button = [UIButton buttonWithType:UIButtonTypeCustom] ;
    jia1Button.frame = CGRectMake(__kScreenWidth / 4 + 9, 20, 60, 36) ;
    [jia1Button setImage:[UIImage imageNamed:@"+.png"] forState:UIControlStateNormal] ;
    jia1Button.tag = 1 ;
    
    [jia1Button addTarget:self action:@selector(jiaBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    [orderTimeBackView addSubview:jia1Button] ;
    
    UIButton *jian1Button = [UIButton buttonWithType:UIButtonTypeCustom] ;
    jian1Button.frame = CGRectMake(__kScreenWidth / 4 + 9, 87, 60, 36) ;
    [jian1Button setImage:[UIImage imageNamed:@"-.png"] forState:UIControlStateNormal] ;
    jian1Button.tag =1 ;
    [jian1Button addTarget:self action:@selector(jianBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    [orderTimeBackView addSubview:jian1Button] ;
    
    monthfield = [self createDatefield:CGRectMake(__kScreenWidth / 4 + 80, 54, 58, 34)] ;
    
    NSDateFormatter *monthFormatter = [[NSDateFormatter alloc] init];
    [monthFormatter setDateFormat:@"MM"];
    NSString *monthString = [monthFormatter stringFromDate:currentDate];
    monthfield.text = monthString ;
    [orderTimeBackView addSubview:monthfield] ;
    
    UIButton *jia2Button = [UIButton buttonWithType:UIButtonTypeCustom] ;
    jia2Button.frame = CGRectMake(__kScreenWidth / 4 + 79, 20, 60, 36) ;
    [jia2Button setImage:[UIImage imageNamed:@"+.png"] forState:UIControlStateNormal] ;
    jia2Button.tag = 2 ;
    [jia2Button addTarget:self action:@selector(jiaBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    [orderTimeBackView addSubview:jia2Button] ;
    
    UIButton *jian2Button = [UIButton buttonWithType:UIButtonTypeCustom] ;
    jian2Button.frame = CGRectMake(__kScreenWidth / 4 + 79, 87, 60, 36) ;
    [jian2Button setImage:[UIImage imageNamed:@"-.png"] forState:UIControlStateNormal] ;
    jian2Button.tag = 2 ;
    [jian2Button addTarget:self action:@selector(jianBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    [orderTimeBackView addSubview:jian2Button] ;
    
    
    dayfield = [self createDatefield:CGRectMake(__kScreenWidth / 4 + 150, 54, 45, 35)] ;
    
    NSDateFormatter *dayFormatter = [[NSDateFormatter alloc] init];
    [dayFormatter setDateFormat:@"dd"];
    NSString *dayString = [dayFormatter stringFromDate:currentDate];
    dayfield.text = dayString ;
    [orderTimeBackView addSubview:dayfield] ;
    
    UIButton *jia3Button = [UIButton buttonWithType:UIButtonTypeCustom] ;
    jia3Button.frame = CGRectMake(__kScreenWidth / 4 + 148.5, 20, 48, 36) ;
    [jia3Button setImage:[UIImage imageNamed:@"+_small.png"] forState:UIControlStateNormal] ;
    jia3Button.tag = 3 ;
    [jia3Button addTarget:self action:@selector(jiaBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    [orderTimeBackView addSubview:jia3Button] ;
    
    UIButton *jian3Button = [UIButton buttonWithType:UIButtonTypeCustom] ;
    jian3Button.frame = CGRectMake(__kScreenWidth / 4 + 148.5, 87, 48, 36) ;
    [jian3Button setImage:[UIImage imageNamed:@"-_small.png"] forState:UIControlStateNormal] ;
    jian3Button.tag = 3 ;
    [jian3Button addTarget:self action:@selector(jianBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    [orderTimeBackView addSubview:jian3Button] ;
    
    //选择上下午
    UIImageView *line1 = [self createline:CGRectMake(__kScreenWidth / 4 + 8, jian3Button.frame.origin.y + jian3Button.frame.size.height + 40, __kScreenWidth *3 / 4 - 36, 1)] ;
    [orderTimeBackView addSubview:line1] ;
    
    UIImageView *line2 = [self createline:CGRectMake(__kScreenWidth / 4 + 8, line1.frame.origin.y + line1.frame.size.height + 40, __kScreenWidth *3 / 4 - 36, 1)] ;
    [orderTimeBackView addSubview:line2] ;
    
    UIImageView *line3 = [self createline:CGRectMake(__kScreenWidth / 4 + 8, line2.frame.origin.y + line2.frame.size.height + 40, __kScreenWidth *3 / 4 - 36, 1)] ;
    [orderTimeBackView addSubview:line3] ;
    
    UIImageView *line4 = [self createline:CGRectMake(__kScreenWidth / 4 + 8, line3.frame.origin.y + line3.frame.size.height + 40, __kScreenWidth *3 / 4 - 36, 1)] ;
    [orderTimeBackView addSubview:line4] ;
    
    UILabel *morningLabel = [self creatlabel:14.0f color:[UIColor whiteColor] alignment:NSTextAlignmentLeft] ;
    morningLabel.frame = CGRectMake(__kScreenWidth / 4 + 8, jian3Button.frame.origin.y + jian3Button.frame.size.height + 13, 40, 16.0f) ;
    morningLabel.text = @"上午" ;
    
    UILabel *afternoonLabel = [self creatlabel:14.0f color:[UIColor whiteColor] alignment:NSTextAlignmentLeft] ;
    afternoonLabel.frame = CGRectMake(__kScreenWidth / 4 + 8, line1.frame.origin.y + line1.frame.size.height + 13, 40, 16.0f) ;
    afternoonLabel.text = @"下午" ;
    
    UILabel *nightLabel = [self creatlabel:14.0f color:[UIColor whiteColor] alignment:NSTextAlignmentLeft] ;
    nightLabel.frame = CGRectMake(__kScreenWidth / 4 + 8, line2.frame.origin.y + line2.frame.size.height + 13, 40, 16.0f) ;
    nightLabel.text = @"晚上" ;
    
    UILabel *alldayLabel = [self creatlabel:14.0f color:[UIColor whiteColor] alignment:NSTextAlignmentLeft] ;
    alldayLabel.frame = CGRectMake(__kScreenWidth / 4 + 8, line3.frame.origin.y + line3.frame.size.height + 13, 40, 16.0f) ;
    alldayLabel.text = @"全天" ;
    [orderTimeBackView addSubview:morningLabel] ;
    [orderTimeBackView addSubview:afternoonLabel] ;
    [orderTimeBackView addSubview:nightLabel] ;
    [orderTimeBackView addSubview:alldayLabel] ;
    
    UILabel *dateLabel = [self creatlabel:18.0f color:[UIColor whiteColor] alignment:NSTextAlignmentRight] ;
    dateLabel.frame = CGRectMake(__kScreenWidth / 4 - 60, 54, 50, 20.0f) ;
    dateLabel.text = @"日期" ;
    [orderTimeBackView addSubview:dateLabel] ;
    
    UILabel *timeLable = [self creatlabel:18.0f color:[UIColor whiteColor] alignment:NSTextAlignmentRight] ;
    timeLable.frame = CGRectMake(__kScreenWidth / 4 - 60, morningLabel.frame.origin.y + 20, 50, 20.0f) ;
    timeLable.text = @"时间" ;
    [orderTimeBackView addSubview:timeLable] ;
    
    
    //上午btn
    morningBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    morningBtn.frame = CGRectMake(orderTimeBackView.frame.size.width - 40, jian3Button.frame.origin.y + jian3Button.frame.size.height + 5, 30, 30) ;
    [morningBtn setBackgroundImage:[UIImage imageNamed:@"picture_list_checkbox_normal_bg"] forState:UIControlStateNormal] ;
    morningBtn.tag = 1 ;
    [morningBtn addTarget:self action:@selector(timeBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    [self timeBtn:morningBtn] ;
    
    //下午btn
    afternoonBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    afternoonBtn.frame = CGRectMake(orderTimeBackView.frame.size.width - 40, line1.frame.origin.y + line1.frame.size.height + 5, 30, 30) ;
    [afternoonBtn setBackgroundImage:[UIImage imageNamed:@"picture_list_checkbox_normal_bg"] forState:UIControlStateNormal] ;
    afternoonBtn.tag = 2 ;
    [afternoonBtn addTarget:self action:@selector(timeBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    
    //晚上btn
    nightBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    nightBtn.frame = CGRectMake(orderTimeBackView.frame.size.width - 40, line2.frame.origin.y + line2.frame.size.height + 5, 30, 30) ;
    [nightBtn setBackgroundImage:[UIImage imageNamed:@"picture_list_checkbox_normal_bg"] forState:UIControlStateNormal] ;
    nightBtn.tag = 3 ;
    [nightBtn addTarget:self action:@selector(timeBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    
    //全天btn
    alldayBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    alldayBtn.frame = CGRectMake(orderTimeBackView.frame.size.width - 40, line3.frame.origin.y + line3.frame.size.height + 5, 30, 30) ;
    [alldayBtn setBackgroundImage:[UIImage imageNamed:@"picture_list_checkbox_normal_bg"] forState:UIControlStateNormal] ;
    alldayBtn.tag = 4 ;
    [alldayBtn addTarget:self action:@selector(timeBtn:) forControlEvents:UIControlEventTouchUpInside] ;
    
    [orderTimeBackView addSubview:morningBtn] ;
    [orderTimeBackView addSubview:afternoonBtn] ;
    [orderTimeBackView addSubview:nightBtn] ;
    [orderTimeBackView addSubview:alldayBtn] ;
    
    //取消btn
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    cancelBtn.frame = CGRectMake((orderTimeBackView.frame.size.width - 240) / 2, line4.frame.origin.y + line4.frame.size.height + 10, 100, 20) ;
    
    [cancelBtn setTitle:@"取消预约" forState:UIControlStateNormal] ;
    [cancelBtn addTarget:self action:@selector(removeMainView) forControlEvents:UIControlEventTouchUpInside] ;
    [orderTimeBackView addSubview:cancelBtn] ;
    
    //确认btn
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    confirmBtn.frame = CGRectMake(cancelBtn.frame.origin.x + cancelBtn.frame.size.width + 40, line4.frame.origin.y + line4.frame.size.height + 10, 100, 20) ;
    [confirmBtn setTitle:@"确认预约" forState:UIControlStateNormal] ;
    [confirmBtn addTarget:self action:@selector(confirmOrder) forControlEvents:UIControlEventTouchUpInside] ;
    [orderTimeBackView addSubview:confirmBtn] ;
    
    
}

//完成工单操作
- (void)haveDoneGD
{
    NSLog(@"接单") ;
    mainView = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.frame] ;
    mainView.backgroundColor = [UIColor blackColor] ;
    mainView.alpha = 0.8 ;
    [[UIApplication sharedApplication].keyWindow addSubview:mainView] ;
    alterview = [[UIView alloc] initWithFrame:CGRectMake(__kScreenWidth / 8, (__kScreenHeight *3/4 - 50) / 2, __kScreenWidth *3/4, __kScreenWidth/4+50)] ;
    alterview.backgroundColor = [UIColor whiteColor] ;
    alterview.layer.cornerRadius = 5.0f ;
    alterview.alpha = 1 ;
    [[UIApplication sharedApplication].keyWindow addSubview:alterview] ;
    
    UILabel *label = [[UILabel alloc] init] ;
    label.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:16.0f] ;
    label.backgroundColor = [UIColor clearColor] ;
    label.textAlignment = NSTextAlignmentLeft ;
    label.textColor = [UIColor grayColor] ;
    label.text = @"确认完成安装？" ;
    label.frame = CGRectMake(20, (alterview.frame.size.height - 60)/2, 150, 18.0f) ;
    [alterview addSubview:label] ;
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal] ;
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
    [cancelBtn setBackgroundImage:[UIImage imageNamed:@"dialog_cancel_normal_btn_bg.png"] forState:UIControlStateNormal] ;
    cancelBtn.frame = CGRectMake(10, alterview.frame.size.height - 60, (alterview.frame.size.width - 40)/2, 40) ;
    [cancelBtn addTarget:self action:@selector(removeMainView) forControlEvents:UIControlEventTouchUpInside] ;
    [alterview addSubview:cancelBtn] ;
    
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [confirmBtn setTitle:@"确认" forState:UIControlStateNormal] ;
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
    [confirmBtn setBackgroundImage:[UIImage imageNamed:@"dialog_enter_normal_btn_bg.png"] forState:UIControlStateNormal] ;
    confirmBtn.frame = CGRectMake(cancelBtn.frame.origin.x + cancelBtn.frame.size.width + 20 , alterview.frame.size.height - 60, (alterview.frame.size.width - 40)/2, 40) ;
    [confirmBtn addTarget:self action:@selector(downloadOfHavedone) forControlEvents:UIControlEventTouchUpInside] ;
    [alterview addSubview:confirmBtn] ;

}

- (void)doorAnZhuang
{
    NSLog(@"接单") ;
    mainView = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.frame] ;
    mainView.backgroundColor = [UIColor blackColor] ;
    mainView.alpha = 0.8 ;
    [[UIApplication sharedApplication].keyWindow addSubview:mainView] ;
    alterview = [[UIView alloc] initWithFrame:CGRectMake(__kScreenWidth / 8, (__kScreenHeight *3/4 - 50) / 2, __kScreenWidth *3/4, __kScreenWidth/4+50)] ;
    alterview.backgroundColor = [UIColor whiteColor] ;
    alterview.layer.cornerRadius = 5.0f ;
    alterview.alpha = 1 ;
    [[UIApplication sharedApplication].keyWindow addSubview:alterview] ;
    
    UILabel *label = [[UILabel alloc] init] ;
    label.font = [UIFont fontWithName:@"AvenirLTStd-Light" size:16.0f] ;
    label.backgroundColor = [UIColor clearColor] ;
    label.textAlignment = NSTextAlignmentLeft ;
    label.textColor = [UIColor grayColor] ;
    label.text = @"是否上门？" ;
    label.frame = CGRectMake(20, (alterview.frame.size.height - 60)/2, 150, 18.0f) ;
    [alterview addSubview:label] ;
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal] ;
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
    [cancelBtn setBackgroundImage:[UIImage imageNamed:@"dialog_cancel_normal_btn_bg.png"] forState:UIControlStateNormal] ;
    cancelBtn.frame = CGRectMake(10, alterview.frame.size.height - 60, (alterview.frame.size.width - 40)/2, 40) ;
    [cancelBtn addTarget:self action:@selector(removeMainView) forControlEvents:UIControlEventTouchUpInside] ;
    [alterview addSubview:cancelBtn] ;
    
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom] ;
    [confirmBtn setTitle:@"确认" forState:UIControlStateNormal] ;
    [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal] ;
    [confirmBtn setBackgroundImage:[UIImage imageNamed:@"dialog_enter_normal_btn_bg.png"] forState:UIControlStateNormal] ;
    confirmBtn.frame = CGRectMake(cancelBtn.frame.origin.x + cancelBtn.frame.size.width + 20 , alterview.frame.size.height - 60, (alterview.frame.size.width - 40)/2, 40) ;
    [confirmBtn addTarget:self action:@selector(downloadOfDoorUP) forControlEvents:UIControlEventTouchUpInside] ;
    [alterview addSubview:confirmBtn] ;
}

- (void)uploadPic
{
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:noimageCount delegate:self];
    imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
    imagePickerVc.selectedAssets = _selectedAssets; // optional, 可选的
    
    // You can get the photos by block, the same as by delegate.
    // 你可以通过block或者代理，来得到用户选择的照片.
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        if (photos.count > 0) {
            [self UploadPicArray:photos] ;
        }
        else{
            NSLog(@"图片张数不足1");
        }
    }];
    
    // Set the appearance
    // 在这里设置imagePickerVc的外观
    // imagePickerVc.navigationBar.barTintColor = [UIColor greenColor];
    // imagePickerVc.oKButtonTitleColorDisabled = [UIColor lightGrayColor];
    // imagePickerVc.oKButtonTitleColorNormal = [UIColor greenColor];
    
    // Set allow picking video & photo & originalPhoto or not
    // 设置是否可以选择视频/图片/原图
    // imagePickerVc.allowPickingVideo = NO;
    // imagePickerVc.allowPickingImage = NO;
    // imagePickerVc.allowPickingOriginalPhoto = NO;
    
    [self presentViewController:imagePickerVc animated:NO completion:nil];
    NSLog(@"上传图片") ;
}

- (void)UploadPicArray:(NSArray *)array
{
    
    NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
    NSInteger uidInt = [[uidDefaults valueForKey:@"uid"] integerValue] ;
    
    NSString *urlString = [NSString stringWithFormat:@"http://test.baogongpo.cn/index.php?s=/home/ServiceManage/uploadfilegddetailaction&gdorderid=%@&pictype=1&uid=%ld",detailModel.orderid,(long)uidInt] ;
    NSLog(@"urlstring:%@",urlString) ;
    
    for (NSInteger i = 0; i < array.count; i++) {
        UIImage *image = array[i] ;
        
        //时间
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"] ;
        NSString *dateStr = [formatter stringFromDate:[NSDate date]] ;
        //地理位置
        NSUserDefaults *uidDefaults = [NSUserDefaults standardUserDefaults] ;
        NSString *address = [uidDefaults valueForKey:@"location"] ;
        NSString *cityStr = [[NSString alloc] init] ;
        NSString *liveStr = [[NSString alloc] init] ;
        for (int i = 0; i < address.length; i++) {
            NSString *temp = [address substringWithRange:NSMakeRange(i, 1)] ;
            if ([temp isEqualToString:@"市"]) {
                cityStr = [address substringToIndex:i+1] ;
                liveStr = [address substringFromIndex:i+1] ;
            }
        }
        NSLog(@"address:%@, cityStr:%@,  liveStr:%@",address,cityStr,liveStr) ;
        UIImage *textImage = [self waterImageWithText:image textLogoColor:dateStr text2:cityStr text3:liveStr];

        
        NSData* imgData = UIImageJPEGRepresentation(textImage, 0.7);
        
        if (i == array.count - 1) {
            [self downloadOfPicUrl:urlString withpicData:imgData isRefresh:YES] ;
        }
        else
        {
            [self downloadOfPicUrl:urlString withpicData:imgData isRefresh:NO] ;
        }
    }

}

#pragma mark - 图片加水印
-(UIImage *)waterImageWithText:(UIImage *)img textLogoColor:(NSString *)text1 text2:(NSString *)text2 text3:(NSString *)text3{
    /////注：此为后来更改，用于显示中文。zyq,2013-5-8
    CGSize size = CGSizeMake(img.size.width, img.size.height); //设置上下文（画布）大小
    UIGraphicsBeginImageContext(size); //创建一个基于位图的上下文(context)，并将其设置为当前上下文
    
    CGContextRef contextRef = UIGraphicsGetCurrentContext(); //获取当前上下文
    
    CGContextTranslateCTM(contextRef, 0, img.size.height); //画布的高度
    CGContextScaleCTM(contextRef, 1.0, -1.0); //画布翻转
    CGContextDrawImage(contextRef, CGRectMake(0, 0, img.size.width, img.size.height), [img CGImage]); //在上下文种画当前图片
    
    CGContextTranslateCTM(contextRef, 0, img.size.height);
    CGContextScaleCTM(contextRef, 1.0, -1.0);
    UIFont *font = [UIFont boldSystemFontOfSize:26];
    
    NSDictionary *attr = @{NSFontAttributeName: font,  //设置字体
                           NSForegroundColorAttributeName : [UIColor whiteColor]   //设置字体颜色
                           };
    [text1 drawInRect:CGRectMake(10, img.size.height*2/3, img.size.width, 30) withAttributes:attr];
    [text2 drawInRect:CGRectMake(10, img.size.height*2/3+30, img.size.width, 30) withAttributes:attr] ;
    [text3 drawInRect:CGRectMake(10, img.size.height*2/3+60, __kScreenWidth, 30) withAttributes:attr] ;
    UIImage *targetimg =UIGraphicsGetImageFromCurrentImageContext(); //从当前上下文种获取图片
    UIGraphicsEndImageContext(); //移除栈顶的基于当前位图的图形上下文。
    return targetimg;
    
}


- (void)deletePic:(id)sender
{
    NSInteger i = [sender tag] ;
    PicModel *model = piclaterArray[i] ;
    [self downloadOfDeletePic:model] ;
}

- (void)previewImage:(id)sender
{
    UITapGestureRecognizer *tap = (UITapGestureRecognizer *)sender;
    
    UIView *view = (UIView *)tap.view;
    
    NSInteger index = view.tag;
    
    NSLog(@"点击了图片%ld",(long)index) ;
    
    PreviewViewController *vc = [[PreviewViewController alloc] init] ;
    vc.array = imageUrlArray ;
    vc.index = index ;
    
    self.hidesBottomBarWhenPushed = YES ;
    [self.navigationController pushViewController:vc animated:NO] ;
    
}

- (void)removeMainView
{
    [mainView removeFromSuperview] ;
    [alterview removeFromSuperview] ;
    [orderTimeBackView removeFromSuperview] ;
    //[messageBackview removeFromSuperview] ;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - 预约操作代理
//日期加
- (void)jiaBtn:(id)sender
{
    NSInteger btnTag = [sender tag] ;
    if (btnTag == 1) {
        NSInteger year = [yearfield.text integerValue] + 1 ;
        yearfield.text = [NSString stringWithFormat:@"%ld",(long)year] ;
        [self textFieldDidEndEditing:yearfield] ;
    }
    if (btnTag == 2) {
        NSInteger year = [monthfield.text integerValue] + 1 ;
        if (year < 10) {
            monthfield.text = [NSString stringWithFormat:@"0%ld",(long)year] ;
        }
        else
        {
            monthfield.text = [NSString stringWithFormat:@"%ld",(long)year] ;
        }
        [self textFieldDidEndEditing:monthfield] ;
        
    }
    if (btnTag == 3) {
        NSInteger year = [dayfield.text integerValue] + 1 ;
        if (year < 10) {
            dayfield.text = [NSString stringWithFormat:@"0%ld",(long)year] ;
        }
        else
        {
            dayfield.text = [NSString stringWithFormat:@"%ld",(long)year] ;
        }
        
        [self textFieldDidEndEditing:dayfield] ;
    }
    
}

//日期减
- (void)jianBtn:(id)sender
{
    NSInteger btnTag = [sender tag] ;
    if (btnTag == 1) {
        NSInteger year = [yearfield.text integerValue] - 1 ;
        yearfield.text = [NSString stringWithFormat:@"%ld",(long)year] ;
        [self textFieldDidEndEditing:yearfield] ;
    }
    if (btnTag == 2) {
        NSInteger year = [monthfield.text integerValue] - 1 ;
        if (year < 10) {
            monthfield.text = [NSString stringWithFormat:@"0%ld",(long)year] ;
            
        }
        else
        {
            monthfield.text = [NSString stringWithFormat:@"%ld",(long)year] ;
        }
        [self textFieldDidEndEditing:monthfield] ;
        
    }
    if (btnTag == 3) {
        NSInteger year = [dayfield.text integerValue] - 1 ;
        if (year < 10) {
            dayfield.text = [NSString stringWithFormat:@"0%ld",(long)year] ;
            
        }
        else
        {
            dayfield.text = [NSString stringWithFormat:@"%ld",(long)year] ;
        }
        
        [self textFieldDidEndEditing:dayfield] ;
    }
    
}

//选择时间
- (void)timeBtn:(id)sender
{
    NSInteger btnTag = [sender tag] ;
    switch (btnTag) {
        case 1:
            [morningBtn setImage:[UIImage imageNamed:@"picture_list_checkbox_press_bg.png"] forState:UIControlStateNormal] ;
            [afternoonBtn setImage:nil forState:UIControlStateNormal] ;
            [nightBtn setImage:nil forState:UIControlStateNormal] ;
            [alldayBtn setImage:nil forState:UIControlStateNormal] ;
            beginTime = @"06:00:00" ;
            endTime = @"12:00:00" ;
            break;
        case 2:
            [morningBtn setImage:nil forState:UIControlStateNormal] ;
            [afternoonBtn setImage:[UIImage imageNamed:@"picture_list_checkbox_press_bg.png"] forState:UIControlStateNormal] ;
            [nightBtn setImage:nil forState:UIControlStateNormal] ;
            [alldayBtn setImage:nil forState:UIControlStateNormal] ;
            beginTime = @"12:00:00" ;
            endTime = @"18:00:00" ;
            break;
        case 3:
            [morningBtn setImage:nil forState:UIControlStateNormal] ;
            [afternoonBtn setImage:nil forState:UIControlStateNormal] ;
            [nightBtn setImage:[UIImage imageNamed:@"picture_list_checkbox_press_bg.png"] forState:UIControlStateNormal] ;
            [alldayBtn setImage:nil forState:UIControlStateNormal] ;
            beginTime = @"18:00:00" ;
            endTime = @"23:59:59" ;
            break;
        case 4:
            [morningBtn setImage:nil forState:UIControlStateNormal] ;
            [afternoonBtn setImage:nil forState:UIControlStateNormal] ;
            [nightBtn setImage:nil forState:UIControlStateNormal] ;
            [alldayBtn setImage:[UIImage imageNamed:@"picture_list_checkbox_press_bg.png"] forState:UIControlStateNormal] ;
            beginTime = @"00:00:00" ;
            endTime = @"23:59:59" ;
            break ;
        default:
            break;
    }
    
    NSLog(@"时间：%@————%@",beginTime,endTime) ;
    
}

- (void)confirmOrder
{
    NSString *beginStr = [NSString stringWithFormat:@"%@-%@-%@ %@",yearfield.text,monthfield.text,dayfield.text,beginTime] ;
    NSString *endStr = [NSString stringWithFormat:@"%@-%@-%@ %@",yearfield.text,monthfield.text,dayfield.text,endTime] ;
    
    NSDateFormatter *endDateFormatter = [[NSDateFormatter alloc] init];
    [endDateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
    NSDate *endGMTDate= [endDateFormatter dateFromString:endStr];
    
    NSTimeZone *endZone = [NSTimeZone systemTimeZone];
    NSInteger endInterval = [endZone secondsFromGMTForDate:endGMTDate];
    NSDate *endDate = [endGMTDate dateByAddingTimeInterval:endInterval];
    
    NSDate *GMTDate = [NSDate date];//获取当前时间，日期
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate:GMTDate];
    NSDate *currentDate = [GMTDate dateByAddingTimeInterval:interval];
    
    NSComparisonResult endResult = [endDate compare:currentDate] ;
    if (endResult == -1) {
        UIButton *errorbtn = [[UIButton alloc] initWithFrame:CGRectMake((__kScreenWidth - 150)/2, __kScreenHeight - 80, 150, 40)] ;
        [errorbtn setTitle:@"当前选择的时间无效" forState:UIControlStateNormal] ;
        errorbtn.titleLabel.font = [UIFont fontWithName:@"AvenirLTStd-Medium" size:14.0f] ;
        errorbtn.layer.cornerRadius = 10 ;
        errorbtn.backgroundColor = [UIColor blackColor] ;
        errorbtn.alpha = 0.8 ;
        [[UIApplication sharedApplication].keyWindow addSubview:errorbtn] ;
        [self performSelector:@selector(clearbtn:) withObject:errorbtn afterDelay:2.0] ;
    }
    else{
        [self downloadOfOrder:detailModel.orderid beginTime:beginStr endTime:endStr] ;
        [self removeMainView] ;
    }
    NSLog(@"endResult:%ld endDate:%@ currentdate:%@", (long)endResult, endDate,currentDate) ;
    
    NSLog(@"beginstr:%@========endstr:%@",beginStr,endStr) ;
}


- (UIImageView *)createline:(CGRect)frame
{
    UIImageView *line = [[UIImageView alloc] initWithFrame:frame] ;
    [line setImage:[UIImage imageNamed:@"set_service_time_heng_divide_line.png"]] ;
    return line ;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
